package qq2564874169.tuaotuao.fx.concurrent;

public class Counter {
    private int value;

    public Counter() {

    }

    public Counter(int num) {
        value = num;
    }

    public synchronized int get() {
        return value;
    }

    public synchronized int add(int num) {
        value += num;
        return value;
    }

    public synchronized int trySet(int old, int value) {
        if (this.value == old) {
            this.value = value;
        }
        return this.value;
    }

    @Override
    public String toString() {
        return String.valueOf(value);
    }
}
